using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace SBPweb.Controls.Windows.Bar
{
	/// <summary>
	/// Class of MenuStrip
	/// </summary>
	[ToolboxBitmap(typeof(System.Windows.Forms.MenuStrip))]
	public partial class MenuStrip : System.Windows.Forms.MenuStrip
	{
		#region Constructors

		public MenuStrip()
		{
			InitializeComponent();
			RegisterEventHandlers();
		}

		private void RegisterEventHandlers()
		{
			this.ItemAdded += new ToolStripItemEventHandler(MenuStrip_ItemAdded);
			this.ItemRemoved += new ToolStripItemEventHandler(MenuStrip_ItemRemoved);
			this.MenuActivate += new EventHandler(MenuStrip_MenuActivate);
			this.MenuDeactivate += new EventHandler(MenuStrip_MenuDeactivate);
		}

		#endregion

		#region Events

		void MenuStrip_MenuDeactivate(object sender, EventArgs e)
		{
			if (this.Parent is ToolStripPanel)
			{
				(this.Parent as ToolStripPanel).Invalidate(true);
			}
			this.Invalidate(true);
		}

		void MenuStrip_MenuActivate(object sender, EventArgs e)
		{
			if (this.Parent is ToolStripPanel)
			{
				(this.Parent as ToolStripPanel).Invalidate(true);
			}
			this.Invalidate(true);
		}

		void MenuStrip_ItemRemoved(object sender, ToolStripItemEventArgs e)
		{
			e.Item.MouseHover -= new EventHandler(Item_MouseHover);
			e.Item.MouseLeave -= new EventHandler(Item_MouseLeave);
			e.Item.MouseUp -= new MouseEventHandler(Item_MouseUp);
			e.Item.MouseDown -= new MouseEventHandler(Item_MouseDown);
		}

		void MenuStrip_ItemAdded(object sender, ToolStripItemEventArgs e)
		{
			e.Item.MouseHover += new EventHandler(Item_MouseHover);
			e.Item.MouseLeave += new EventHandler(Item_MouseLeave);
			e.Item.MouseUp += new MouseEventHandler(Item_MouseUp);
			e.Item.MouseDown += new MouseEventHandler(Item_MouseDown);
		}

		void Item_MouseDown(object sender, MouseEventArgs e)
		{
			if (this.Parent is ToolStripPanel)
			{
				(this.Parent as ToolStripPanel).Invalidate(true);
			}
			this.Invalidate(true);
		}

		void Item_MouseUp(object sender, MouseEventArgs e)
		{
			if (this.Parent is ToolStripPanel)
			{
				(this.Parent as ToolStripPanel).Invalidate(true);
			}
			this.Invalidate(true);
		}

		void Item_MouseLeave(object sender, EventArgs e)
		{
			if (this.Parent is ToolStripPanel)
			{
				(this.Parent as ToolStripPanel).Invalidate(true);
			}
			this.Invalidate(true);
		}

		void Item_MouseHover(object sender, EventArgs e)
		{
			if (this.Parent is ToolStripPanel)
			{
				(this.Parent as ToolStripPanel).Invalidate(true);
			}
			this.Invalidate(true);
		}

		#endregion
	}
}
